package com.shadow.ignorDependencyInterface.test;

import com.shadow.ignorDependencyInterface.test.pojo.ClassA;
import com.shadow.ignorDependencyInterface.test.pojo.InterfaceC;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author VernHe
 * @date 2021年09月16日 13:53
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

//		ScannedGenericBeanDefinition classA = (ScannedGenericBeanDefinition) beanFactory.getBeanDefinition("a");
//		// 根据类型自动注入
//		classA.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
//
//		// 忽略XXX接口的setXXX方法，也就是说不会执行实现了这个XXX接口的setXX方法
//		beanFactory.ignoreDependencyInterface(InterfaceC.class);
//		beanFactory.getBean(ClassA.class).exec();

		// 测试冻结
		AbstractBeanDefinition d = (AbstractBeanDefinition) beanFactory.getBeanDefinition("classD");
		beanFactory.freezeConfiguration();
//		d.setLazyInit(true);
		d.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	}
}
